package com.zh.netty.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * 传统java IO 的客户端
 */
public class OldIOClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 7001);
        String fileName = "D:\\sys_dict_item.sql";
        FileInputStream inputStream = new FileInputStream(fileName);

        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

        byte[] byteArray = new byte[4096];
        long readCount;
        long total = 0L;
        long startTime = System.currentTimeMillis();

        while ((readCount = inputStream.read(byteArray)) >= 0){
            total += readCount;
            dataOutputStream.write(byteArray);
        }
        System.out.println("发送总字节数："+total+", 耗时："+(System.currentTimeMillis() - startTime));

        dataOutputStream.close();
        socket.close();
        inputStream.close();
    }
}
